/*
ID:luongho3
LANG:JAVA
TASK:frameup
 */

import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;


public class frameup {

	int width, height;
	String[] map;
	int[][] rectInfo = new int[30][5]; // up, down, left, right
	int[][] gra = new int[30][30];
	int[] inDeg = new int[30];
	boolean[] inFrame = new boolean[30];
	int nRect;
	int[][] res = new int[30][30];

	public static void main(String[] args) throws Exception {
		
		frameup prob = new frameup();
		
		prob.read();
		
//		System.out.println(prob.height + " " + prob.width);
//		for (int i=1;i<=prob.height;++i) {
//			System.out.println(prob.map[i]);;
//		}
		
		prob.solve();
		
	}
	
	public void read() throws Exception {
		Scanner scanner = new Scanner(new File("frameup.in"));
		height = scanner.nextInt();
		width = scanner.nextInt();
		map = new String[height+1];
		for (int i=1;i<=height;++i) {
			map[i] = scanner.next();
		}
	}
	
	public void solve() throws Exception {
		for (int i=1;i<=29;++i) {
			rectInfo[i][1] = height+1;
			rectInfo[i][2] = 0;
			rectInfo[i][3] = width+1;
			rectInfo[i][4] = 0;
		}
		
		nRect = 0; 
		
		for (int i=1;i<=height;++i) {
			for (int j=1;j<=width;++j) {
				char c = map[i].charAt(j-1);
				if (c != '.') {
					int idx = (c - 'A') + 1;
					inFrame[idx] = true;
					if (i < rectInfo[idx][1]) {
						rectInfo[idx][1] = i;
					}
					if (i > rectInfo[idx][2]) {
						rectInfo[idx][2] = i;
					}
					if (j < rectInfo[idx][3]) {
						rectInfo[idx][3] = j;
					}
					if (j > rectInfo[idx][4]) {
						rectInfo[idx][4] = j;
					}
				}
			}
		}
		
		for (int i=1;i<=29;++i) {
			if (rectInfo[i][2] != 0) {
				nRect++;
				char c = (char) (i + 'A' - 1);
				for (int j=rectInfo[i][3];j<=rectInfo[i][4];++j) {
					char ch = map[rectInfo[i][1]].charAt(j-1);
					if (ch != c) {
						int idx = ch - 'A' + 1;
						gra[i][idx] = 1;
					}
					ch = map[rectInfo[i][2]].charAt(j-1);
					if (ch != c) {
						int idx = ch - 'A' + 1;
						gra[i][idx] = 1;
					}
				}
				for (int j=rectInfo[i][1];j<=rectInfo[i][2];++j) {
					char ch = map[j].charAt(rectInfo[i][3]-1);
					if (ch != c) {
						int idx = ch - 'A' + 1;
						gra[i][idx] = 1;
					}
					ch = map[j].charAt(rectInfo[i][4]-1);
					if (ch != c) {
						int idx = ch - 'A' + 1;
						gra[i][idx] = 1;
					}
				}
			}
		}
		
		for (int i=1;i<30;++i) {
			for (int j=1;j<30;++j) {
				if (gra[i][j] == 1) {
					inDeg[j]++;
//					System.out.println((char)(i+'A'-1) + " --> " + (char)(j+'A'-1));
				}
			}
		}
		
		PrintStream ps = new PrintStream(new File("frameup.out"));
		System.setOut(ps);
		for (int i=1;i<30;++i) {
			if (inFrame[i]) {
				if (inDeg[i] == 0) {
					String res = (char)(i+'A'-1) + "";
					inFrame[i] = false;
					recurse(i,res);
					inFrame[i] = true;
				}
			}
		}
		ps.close();
	}

	private void recurse(int n, String res) {
		if (res.length() == nRect) {
			System.out.println(res);
			return;
		}
		for (int i=1;i<30;++i) {
			if (inFrame[i] && gra[n][i] == 1) {
				gra[n][i] = -1;
				inDeg[i]--;
			}
		}
		for (int i=1;i<30;++i) {
			if (inFrame[i] && inDeg[i] == 0) {
				inFrame[i] = false;
				recurse(i,res + (char)(i+'A'-1));
				inFrame[i] = true;
			}
		}
		for (int i=1;i<30;++i) {
			if (inFrame[i] && gra[n][i] == -1) {
				gra[n][i] = 1;
				inDeg[i]++;
			}
		}
	}
}
